package com.team2.shoppingService;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

import com.team2.shared.SharedConstants;


public class Configuration {
	static long requestCounter=0;
	private static Configuration instance = new Configuration();
	
	//paths
	public static final String TEMPPATH="/TEMP/";
	public static final String REALTEMPPATH = "C:/CyberTEMP/";
	public static String CONTEXT="";
	
	public static void setContext(String context) {
		CONTEXT = context;
	}
	//constant numbers
	public static final int NUMBER_OF_IMAGE_THREAD=5;
	public static final int MAX_NUMBER_PRODUCTS=40;
	
	
	private static HashMap<String, String> storeNameToConfigFile;
	private static HashMap<String, List<String>> categoryToName;
	
	private static String pathPrefix="";
	
	public static String getPathPrefix() {
		return pathPrefix;
	}
	synchronized public static long getNextRequestNumber(){
		return ++requestCounter;
	}
	public static void setPathPrefix(String pathPrefixName) {
		pathPrefix = pathPrefixName;
		updateConfigFileMapping();
		
	}

	private Configuration(){
		storeNameToConfigFile = new HashMap<String, String>();
		
		categoryToName = new HashMap<String, List<String>>();
		initCategoryMap();
		updateConfigFileMapping();
		
	}
	private static void updateConfigFileMapping(){
		storeNameToConfigFile.put(SharedConstants.FUTURE_SHOP,pathPrefix+"futureShopCatalog.xml");
		storeNameToConfigFile.put(SharedConstants.CHAPTERS,pathPrefix+"chaptersCatalog.xml");
		storeNameToConfigFile.put(SharedConstants.SEARS,pathPrefix+"searsCatalog.xml");
		storeNameToConfigFile.put(SharedConstants.THE_BAY,pathPrefix+"theBayCatalog.xml");
		storeNameToConfigFile.put(SharedConstants.WALMART,pathPrefix+"walmartCatalog.xml");
		storeNameToConfigFile.put(SharedConstants.BESTBUY,pathPrefix+"bestBuyCatalog.xml");
		storeNameToConfigFile.put(SharedConstants.LONDON_DRUG,pathPrefix+"londonDrugsCatalog.xml");
		
	}
	
	private void initCategoryMap(){
		List<String> tempList;
		tempList = new ArrayList<String> ();
		tempList.add(SharedConstants.FUTURE_SHOP);
		tempList.add(SharedConstants.BESTBUY);
		tempList.add(SharedConstants.WALMART);
		categoryToName.put(SharedConstants.ELECTRONICS, tempList);
		
		tempList = new ArrayList<String> ();
		tempList.add(SharedConstants.CHAPTERS);
		tempList.add(SharedConstants.WALMART);
		categoryToName.put(SharedConstants.BOOK, tempList);
		
		tempList = new ArrayList<String> ();
		tempList.add(SharedConstants.THE_BAY);
		tempList.add(SharedConstants.WALMART);
		tempList.add(SharedConstants.SEARS);
		categoryToName.put(SharedConstants.APPAREL, tempList);
		
		tempList = new ArrayList<String> ();
		tempList.add(SharedConstants.SEARS);
		tempList.add(SharedConstants.WALMART);
		categoryToName.put(SharedConstants.GROCERY, tempList);
		
		tempList = new ArrayList<String> ();
		tempList.add(SharedConstants.FUTURE_SHOP);
		tempList.add(SharedConstants.BESTBUY);
		tempList.add(SharedConstants.WALMART);
		categoryToName.put(SharedConstants.APPLIANCES, tempList);
		
		tempList = new ArrayList<String> ();
		tempList.add(SharedConstants.WALMART);
		tempList.add(SharedConstants.LONDON_DRUG);
		categoryToName.put(SharedConstants.OTHER, tempList);
		
	}
	public static String getBarcodeConfigFile(){
		return pathPrefix+"barcodeSearch.xml";
	}
	public static List<String> getStoreNameFromCategory(String category){
		List<String> result = new ArrayList<String>();
		if(category==null){
			result.add(SharedConstants.BESTBUY);
			return result;
		}
		List<String> list = categoryToName.get(category);
		if(list==null){
			return new ArrayList<String>();
		}
		return list;
	}
	@Deprecated
	public static Collection<String> getProviderList(){
		return storeNameToConfigFile.keySet() ;
	}
	public static String getParserConfig(String storeName){
		return storeNameToConfigFile.get(storeName);
	}
	
	

}
